TextView: Use saner coordinate space in draw_layer.
authorAlexander Larsson <alexl@redhat.com>
Mon, 9 Nov 2015 21:18:05 +0000 (22:18 +0100)
committerAlexander Larsson <alexl@redhat.com>
Tue, 10 Nov 2015 07:39:47 +0000 (08:39 +0100)
When I added the draw_layer vfunc it accidentally got passed a cairo_t
that was configured with to draw in the viewport coordinate space (rather
than the buffer coordinate space). This makes things unnecessary complex,
because you have to convert between the two.

The pixel cache is shared between the text and the layers, so there is
no way to use draw_layer to get a stationary overlay effect. Thus it makes
much more sense for the draw_layer vfunc to draw in the buffer space.

Just changing this would break ABI for existing code, so this is fixed
by adding new layer types and deprecating the old ones.

Also, we use the new layer types to fix gtk3-widget-factory.

https://bugzilla.gnome.org/show_bug.cgi?id=757856

demos/widget-factory/widget-factory.c
gtk/gtktextview.c
gtk/gtktextview.h

index 573f266e3c1e3654f0b9fe31cf3875b50ad3f51c..ee2ae5ae00122e091d4cfb6d70ad9c0bc030e747 100644 (file)
@@ -1034,7 +1034,7 @@ my_tv_draw_layer (GtkTextView      *widget,
 {
   MyTextView *tv = (MyTextView *)widget;
 
-  if (layer == GTK_TEXT_VIEW_LAYER_BELOW && tv->surface)
+  if (layer == GTK_TEXT_VIEW_LAYER_BELOW_TEXT && tv->surface)
     {
       cairo_save (cr);
       cairo_set_source_surface (cr, tv->surface, 0.0, 0.0);
index 3b8f16ea5e6ffe2f9e6b1e506720b0df2967f1e9..773a87f2cf022551b8794aa015a5d0654dadd465 100644 (file)
@@ -5813,6 +5813,11 @@ draw_text (cairo_t  *cr,
       cairo_save (cr);
       GTK_TEXT_VIEW_GET_CLASS (text_view)->draw_layer (text_view, GTK_TEXT_VIEW_LAYER_BELOW, cr);
       cairo_restore (cr);
+
+      cairo_save (cr);
+      cairo_translate (cr, -text_view->priv->xoffset, -text_view->priv->yoffset);
+      GTK_TEXT_VIEW_GET_CLASS (text_view)->draw_layer (text_view, GTK_TEXT_VIEW_LAYER_BELOW_TEXT, cr);
+      cairo_restore (cr);
     }
 
   gtk_text_view_paint (widget, cr);
@@ -5822,6 +5827,11 @@ draw_text (cairo_t  *cr,
       cairo_save (cr);
       GTK_TEXT_VIEW_GET_CLASS (text_view)->draw_layer (text_view, GTK_TEXT_VIEW_LAYER_ABOVE, cr);
       cairo_restore (cr);
+
+      cairo_save (cr);
+      cairo_translate (cr, -text_view->priv->xoffset, -text_view->priv->yoffset);
+      GTK_TEXT_VIEW_GET_CLASS (text_view)->draw_layer (text_view, GTK_TEXT_VIEW_LAYER_ABOVE_TEXT, cr);
+      cairo_restore (cr);
     }
 }
 
index 41a54ba406a5304db2eb855b21cc674a5505f7da..203fcfba1ffaedf50286859e9afe2e61e49ecb3b 100644 (file)
@@ -69,8 +69,10 @@ typedef enum
 
 /**
  * GtkTextViewLayer:
- * @GTK_TEXT_VIEW_LAYER_BELOW: The layer rendered below the text (but above the background).
- * @GTK_TEXT_VIEW_LAYER_ABOVE: The layer rendered above the text.
+ * @GTK_TEXT_VIEW_LAYER_BELOW: Old deprecated layer, use %GTK_TEXT_VIEW_LAYER_BELOW_TEXT instead
+ * @GTK_TEXT_VIEW_LAYER_ABOVE: Old deprecated layer, use %GTK_TEXT_VIEW_LAYER_ABOVE_TEXT instead
+ * @GTK_TEXT_VIEW_LAYER_BELOW_TEXT: The layer rendered below the text (but above the background).  Since: 3.20
+ * @GTK_TEXT_VIEW_LAYER_ABOVE_TEXT: The layer rendered above the text.  Since: 3.20
  *
  * Used to reference the layers of #GtkTextView for the purpose of customized
  * drawing with the ::draw_layer vfunc.
@@ -78,7 +80,9 @@ typedef enum
 typedef enum
 {
   GTK_TEXT_VIEW_LAYER_BELOW,
-  GTK_TEXT_VIEW_LAYER_ABOVE
+  GTK_TEXT_VIEW_LAYER_ABOVE,
+  GTK_TEXT_VIEW_LAYER_BELOW_TEXT,
+  GTK_TEXT_VIEW_LAYER_ABOVE_TEXT
 } GtkTextViewLayer;
 
 /**
@@ -149,7 +153,10 @@ struct _GtkTextView
  * @draw_layer: The draw_layer vfunc is called before and after the text
  *   view is drawing its own text. Applications can override this vfunc
  *   in a subclass to draw customized content underneath or above the
- *   text. Since: 3.14
+ *   text. In the %GTK_TEXT_VIEW_LAYER_BELOW_TEXT and %GTK_TEXT_VIEW_LAYER_ABOVE_TEXT
+ *   the drawing is done in the buffer coordinate space, but the older (deprecated)
+ *   layers %GTK_TEXT_VIEW_LAYER_BELOW and %GTK_TEXT_VIEW_LAYER_ABOVE work in viewport
+ *   coordinates, which makes them unnecessarily hard to use. Since: 3.14
  * @extend_selection: The class handler for the #GtkTextView::extend-selection
  *   signal. Since 3.16
  */